home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCTAGS15.ARJ / FLAGS.C < prev    next >
C/C++ Source or Header  |  1991-10-04  |  11KB  |  389 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: flags.c
  5.    Author: J. Kercheval
  6.    Created: Thu, 09/05/1991  20:15:26
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Thu, 09/05/1991  20:19:46  creation
  12.    J. Kercheval  Wed, 09/11/1991  01:43:31  add support for -cx
  13.    J. Kercheval  Tue, 09/17/1991  19:39:31  add support for case_sensitive flag
  14.    J. Kercheval  Fri, 10/04/1991  10:43:10  add ck flag
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #include "flags.h"
  21. #include "log.h"
  22.  
  23.  
  24. /*----------------------------------------------------------------------------
  25.  *
  26.  * init_ASM_flagsa() set the initial values of the ASM language option flags
  27.  *
  28.  ---------------------------------------------------------------------------*/
  29.  
  30. void init_ASM_flags(Flags * flags)
  31. {
  32.     flags->af = TRUE;           /* parse procedure labels by default */
  33.     flags->al = TRUE;           /* parse local labels by default */
  34.     flags->am = TRUE;           /* parse macro labels by default */
  35.     flags->as = TRUE;           /* parse struc labels by default */
  36.     flags->au = TRUE;           /* parse union labels by default */
  37.     flags->ad = TRUE;           /* parse catstr labels by default */
  38. }
  39.  
  40.  
  41. /*----------------------------------------------------------------------------
  42.  *
  43.  * init_C_flags() set the initial values of the c language option flags
  44.  *
  45.  ---------------------------------------------------------------------------*/
  46.  
  47. void init_C_flags(Flags * flags)
  48. {
  49.     flags->cf = TRUE;           /* parse function calls by default */
  50.     flags->cp = TRUE;           /* parse function prototypes by default */
  51.     flags->cm = TRUE;           /* parse macros by default */
  52.     flags->cs = TRUE;           /* parse global structs by default */
  53.     flags->ct = TRUE;           /* parse global typedefs default */
  54.     flags->ce = TRUE;           /* parse global enums by default */
  55.     flags->ck = TRUE;           /* parse global enum constants by default */
  56.     flags->cu = TRUE;           /* parse global unions by default */
  57.     flags->cv = TRUE;           /* parse global variables by default */
  58.     flags->cc = TRUE;           /* parse global classes by default */
  59.     flags->cd = TRUE;           /* parse defines by default */
  60.     flags->cx = TRUE;           /* parse externs by default */
  61.     flags->ci = TRUE;           /* parse statics by default */
  62. }
  63.  
  64.  
  65. /*----------------------------------------------------------------------------
  66.  *
  67.  * init_output_flags() set the initial values of the output option flags
  68.  *
  69.  ---------------------------------------------------------------------------*/
  70.  
  71. void init_output_flags(Flags * flags)
  72. {
  73.     flags->oe = TRUE;           /* The Epsilon tags format is default */
  74.     flags->og = FALSE;          /* GNU tags format used in GNU EMACS */
  75.     flags->os = FALSE;          /* Space delimited format */
  76.     flags->om = FALSE;          /* MicroSoft Error format */
  77. }
  78.  
  79.  
  80. /*----------------------------------------------------------------------------
  81.  *
  82.  * init_flags() set the initial values of the all option flags in FLAGS struct
  83.  *
  84.  ---------------------------------------------------------------------------*/
  85.  
  86. void init_flags(Flags * flags)
  87. {
  88.     /* tag_type is initially C type parsing */
  89.     flags->tag_type = C;
  90.  
  91.     /* normally use the fully qualified pathname */
  92.     flags->use_relative_pathnames = FALSE;
  93.  
  94.     /* normally we are noisy and verbose */
  95.     flags->quiet = FALSE;
  96.  
  97.     /* normal logging defaults to overwrite */
  98.     flags->log_overwrite = TRUE;
  99.  
  100.     /* normally we will sort the output to remove duplicate lines */
  101.     flags->sort_tags = TRUE;
  102.  
  103.     /* normally a case insensitive sort is performed */
  104.     flags->case_sensitive = FALSE;
  105.  
  106.     /* normally we will output to stdout */
  107.     flags->output_file = FALSE;
  108.  
  109.     /* init the language specific flags */
  110.     init_ASM_flags(flags);
  111.     init_C_flags(flags);
  112.  
  113.     /* init the output flags */
  114.     init_output_flags(flags);
  115. }
  116.  
  117.  
  118. /*----------------------------------------------------------------------------
  119.  *
  120.  * parse_ASM_flags() set the option flags for ASM command line switch
  121.  *
  122.  ---------------------------------------------------------------------------*/
  123.  
  124. void parse_ASM_flags(char *argv, Flags * flags)
  125. {
  126.     int i, end;
  127.     char message[80];
  128.  
  129.     /* set tag_type */
  130.     if (flags->tag_type != MERGE && flags->tag_type != SORT) {
  131.         flags->tag_type = ASM;
  132.         log_message("# Using ASM style tagging");
  133.     }
  134.     else {
  135.         return;
  136.     }
  137.  
  138.     /* determine the number of modifiers */
  139.     end = strlen(argv);
  140.  
  141.     /* if customized parsing, all flags start off false */
  142.     if (end > 2) {
  143.  
  144.         flags->af = FALSE;
  145.         flags->am = FALSE;
  146.         flags->al = FALSE;
  147.         flags->as = FALSE;
  148.         flags->au = FALSE;
  149.         flags->ad = FALSE;
  150.     }
  151.     else {
  152.  
  153.         /* init flags */
  154.         init_ASM_flags(flags);
  155.     }
  156.  
  157.     /* parse the standard modifiers */
  158.     for (i = 2; i < end; i++) {
  159.  
  160.         /* set flags as required */
  161.         switch (argv[i]) {
  162.  
  163.             case 'f':           /* proc labels */
  164.             case 'F':
  165.                 flags->af = TRUE;
  166.                 break;
  167.  
  168.             case 'l':           /* local labels */
  169.             case 'L':
  170.                 flags->al = TRUE;
  171.                 break;
  172.  
  173.             case 'm':           /* macros */
  174.             case 'M':
  175.                 flags->am = TRUE;
  176.                 break;
  177.  
  178.             case 's':           /* struc labels */
  179.             case 'S':
  180.                 flags->as = TRUE;
  181.                 break;
  182.  
  183.             case 'u':           /* union labels */
  184.             case 'U':
  185.                 flags->au = TRUE;
  186.                 break;
  187.  
  188.             case 'd':           /* data definition labels */
  189.             case 'D':
  190.                 flags->ad = TRUE;
  191.                 break;
  192.  
  193.             default:
  194.                 sprintf(message,
  195.                         "# Ignoring unknown ASM switch modifier ( %c )",
  196.                         argv[i]);
  197.                 log_message(message);
  198.                 break;
  199.         }
  200.     }
  201. }
  202.  
  203.  
  204. /*----------------------------------------------------------------------------
  205.  *
  206.  * parse_C_flags() set the option flags for C command line switch
  207.  *
  208.  ---------------------------------------------------------------------------*/
  209.  
  210. void parse_C_flags(char *argv, Flags * flags)
  211. {
  212.     int i, end;
  213.     char message[80];
  214.  
  215.     /* set tag_type */
  216.     if (flags->tag_type != MERGE && flags->tag_type != SORT) {
  217.         flags->tag_type = C;
  218.         log_message("# Using C style tagging");
  219.     }
  220.     else {
  221.         return;
  222.     }
  223.  
  224.     /* determine the number of modifiers */
  225.     end = strlen(argv);
  226.  
  227.     /* if customized parsing, all flags start off false */
  228.     if (end > 2) {
  229.  
  230.         flags->cf = FALSE;
  231.         flags->cp = FALSE;
  232.         flags->cm = FALSE;
  233.         flags->cs = FALSE;
  234.         flags->ct = FALSE;
  235.         flags->ce = FALSE;
  236.         flags->ck = FALSE;
  237.         flags->cu = FALSE;
  238.         flags->cv = FALSE;
  239.         flags->cc = FALSE;
  240.         flags->cd = FALSE;
  241.         flags->cx = FALSE;
  242.         flags->ci = FALSE;
  243.     }
  244.     else {
  245.  
  246.         /* init flags */
  247.         init_C_flags(flags);
  248.     }
  249.  
  250.     /* parse the switch modifiers */
  251.     for (i = 2; i < end; i++) {
  252.  
  253.         /* set flags as required */
  254.         switch (argv[i]) {
  255.             case 'f':           /* function calls (procedures) */
  256.             case 'F':
  257.                 flags->cf = TRUE;
  258.                 break;
  259.  
  260.             case 'p':           /* function calls (procedures) */
  261.             case 'P':
  262.                 flags->cp = TRUE;
  263.                 break;
  264.  
  265.             case 'm':           /* global macros */
  266.             case 'M':
  267.                 flags->cm = TRUE;
  268.                 break;
  269.  
  270.             case 's':           /* global struct */
  271.             case 'S':
  272.                 flags->cs = TRUE;
  273.                 break;
  274.  
  275.             case 't':           /* global typedef */
  276.             case 'T':
  277.                 flags->ct = TRUE;
  278.                 break;
  279.  
  280.             case 'e':           /* global enum */
  281.             case 'E':
  282.                 flags->ce = TRUE;
  283.                 break;
  284.  
  285.             case 'k':           /* global enum constants */
  286.             case 'K':
  287.                 flags->ck = TRUE;
  288.                 break;
  289.  
  290.             case 'u':           /* global union */
  291.             case 'U':
  292.                 flags->cu = TRUE;
  293.                 break;
  294.  
  295.             case 'v':           /* global variables */
  296.             case 'V':
  297.                 flags->cv = TRUE;
  298.                 break;
  299.  
  300.             case 'c':           /* global classes */
  301.             case 'C':
  302.                 flags->cc = TRUE;
  303.                 break;
  304.  
  305.             case 'd':           /* defines */
  306.             case 'D':
  307.                 flags->cd = TRUE;
  308.                 break;
  309.  
  310.             case 'x':           /* extern defines */
  311.             case 'X':
  312.                 flags->cx = TRUE;
  313.                 break;
  314.  
  315.             case 'i':           /* static declarations */
  316.             case 'I':
  317.                 flags->ci = TRUE;
  318.                 break;
  319.  
  320.             default:
  321.                 sprintf(message,
  322.                         "# Ignoring unknown C switch modifier ( %c )",
  323.                         argv[i]);
  324.                 log_message(message);
  325.                 break;
  326.         }
  327.     }
  328. }
  329.  
  330.  
  331. /*----------------------------------------------------------------------------
  332.  *
  333.  * parse_output_flag() set the option flag for output format, These formats
  334.  * are mutually exclusive from the point of view of this routine.
  335.  *
  336.  ---------------------------------------------------------------------------*/
  337.  
  338. void parse_output_flags(char *argv, Flags * flags)
  339. {
  340.     int i, end;
  341.  
  342.     /* init flags */
  343.     init_output_flags(flags);
  344.  
  345.     end = strlen(argv);
  346.  
  347.     /* parse the switch modifiers */
  348.     for (i = 2; i < end; i++) {
  349.  
  350.         /* set flags as required */
  351.         switch (argv[i]) {
  352.             case 'e':           /* Use Epsilon format */
  353.             case 'E':
  354.                 flags->oe = TRUE;
  355.                 flags->og = FALSE;
  356.                 flags->os = FALSE;
  357.                 flags->om = FALSE;
  358.                 break;
  359.  
  360.             case 'g':           /* Use GNU format */
  361.             case 'G':
  362.                 flags->oe = FALSE;
  363.                 flags->og = TRUE;
  364.                 flags->os = FALSE;
  365.                 flags->om = FALSE;
  366.                 break;
  367.  
  368.             case 's':           /* Use Space Delimite format */
  369.             case 'S':
  370.                 flags->oe = FALSE;
  371.                 flags->og = FALSE;
  372.                 flags->os = TRUE;
  373.                 flags->om = FALSE;
  374.                 break;
  375.  
  376.             case 'm':           /* Use Space Delimite format */
  377.             case 'M':
  378.                 flags->oe = FALSE;
  379.                 flags->og = FALSE;
  380.                 flags->os = FALSE;
  381.                 flags->om = TRUE;
  382.                 break;
  383.  
  384.             default:
  385.                 break;
  386.         }
  387.     }
  388. }
  389.